# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Kaiting Chen <kaitocracy@gmail.com>
# Contributor: Roberto Alsina <ralsina@kde.org>

pkgname=nsd
pkgver=4.7.0
pkgrel=1
pkgdesc="Authoritative only, high performance and simple DNS server"
arch=(loong64 x86_64)
url="https://www.nlnetlabs.nl/nsd/"
license=(BSD)
depends=(openssl libevent fstrm protobuf-c systemd-libs)
makedepends=(systemd)
validpgpkeys=(EDFAA3F2CA4E6EB05681AF8E9F6F1C2D7E045F8D  # W.C.A. Wijngaards <wouter@nlnetlabs.nl>
              C3E356788FAD0179D872D092BA811E62E7194568)
source=("https://www.nlnetlabs.nl/downloads/${pkgname}/${pkgname}-${pkgver}.tar.gz"{,.asc}
        nsd.service
        nsd.sysusers
        nsd.tmpfiles)
sha256sums=('8faca44e299ad2915fa000887ab1632631ea68709c62ce35f110bfe721ecf214'
            'SKIP'
            '51dcf15195be0f6a4154a29ad882eabe180b2413e6b3cadbb1535885ff0d4dfa'
            '12ce2a05fbb23bb38c31933530a7773f796e250691843b9da76f178f5e7c94f5'
            '07a31cecdc787c7ef44018dfc696115bd7b5d44b6e93f56c6c08ed0887d51579')
install=nsd.install

prepare() {
  cd ${pkgname}-${pkgver}
  autoreconf -vfi
}

build() {
  cd ${pkgname}-${pkgver}
  ./configure \
    --prefix=/ \
    --sbindir=/usr/bin \
    --datarootdir=/usr/share \
    --with-pidfile=/run/nsd/nsd.pid \
    --with-user="" \
    --enable-ratelimit \
    --enable-relro-now \
    --enable-pie \
    --enable-dnstap \
    --enable-systemd \
    --enable-tcp-fastopen
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install
  rmdir "${pkgdir}"/{tmp,run{/nsd,},var{/db{/nsd,},}}

  rm doc/differences.pdf
  install -d "${pkgdir}"/usr/share/{doc,licenses}/"${pkgname}"
  install -m644 doc/* "${pkgdir}"/usr/share/doc/"${pkgname}"
  ln -s ../../doc/"${pkgname}"/LICENSE "${pkgdir}"/usr/share/licenses/"${pkgname}"/LICENSE
  install -Dm644 ../nsd.service -t "${pkgdir}"/usr/lib/systemd/system/
  install -Dm644 ../nsd.sysusers "${pkgdir}"/usr/lib/sysusers.d/nsd.conf
  install -Dm644 ../nsd.tmpfiles "${pkgdir}"/usr/lib/tmpfiles.d/nsd.conf
}
